package starComponent.parallelcoordinates;

import java.awt.Color;
import java.util.HashMap;

import starComponent.E_PossibleBranches;

import data.visu.structures.ValueAndString;
import data.visu.utils.Numbers;

/**
 * @author Charles Perin
 * 11 avr. 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 */
public class ParallelLadder {

	private E_PossibleBranches branchType;

	private double min, max, step;

	private Color tickColor, labelColor;

	private boolean paintTicks, paintLabels;

	private HashMap<Double, ParallelLadderTick> ladderMap;


	/**
	 * Constructeur d'une echelle lineaire
	 * @param min la valeur min de l'echelle
	 * @param max la valeur max de l'echelle
	 * @param step le pas de l'echelle, pris en compte uniquement si echelle lineaire
	 * @param paintTicks vrai si dessin des ticks
	 * @param paintLabels vrai si dessin des valeurs
	 * @param tickColor la couleur des ticks
	 * @param labelColor la couleur des labels
	 */
	public ParallelLadder(E_PossibleBranches branchType, boolean paintTicks, boolean paintLabels, Color tickColor, Color labelColor){
		this.tickColor = tickColor;
		this.labelColor = labelColor;
		this.ladderMap = new HashMap<Double, ParallelLadderTick>();
		this.step=branchType.getStep();
		this.min=branchType.getMinValue();
		this.max=branchType.getMaxValue();
		this.paintLabels = paintLabels;
		this.paintTicks=paintTicks;
		this.branchType = branchType;
	}

	public void updateLadderMap(A_ParallelBranch branch) {
		ladderMap.clear();

		switch(branchType.getType()){
		case E_PossibleBranches.QUANTITATIVE_SLIDER:
		case E_PossibleBranches.QUANTITATIVE_BISLIDER:
			for(double val=min; val<=max;val+=step){
				ladderMap.put(val, new ParallelLadderTick(branch, val, Double.toString(Numbers.roundDouble(val, 2))));
			}
			break;

		case E_PossibleBranches.QUALITATIVE_SLIDER:
		case E_PossibleBranches.QUALITATIVE_BISLIDER:
			for(ValueAndString vs:branchType.getLabels()){
				ladderMap.put((double) vs.getValue(), new ParallelLadderTick(branch, vs.getValue(), vs.getString()));
			}
			break;
		}
	}

	public double getMin() {
		return min;
	}

	public void setMin(double min) {
		this.min = min;
	}

	public double getMax() {
		return max;
	}

	public void setMax(double max) {
		this.max = max;
	}

	public double getStep() {
		return step;
	}

	public void setStep(double step) {
		this.step = step;
	}

	public boolean isPaintTicks() {
		return paintTicks;
	}

	public void setPaintTicks(boolean paintTicks) {
		this.paintTicks = paintTicks;
	}

	public boolean isPaintLabels() {
		return paintLabels;
	}

	public void setPaintLabels(boolean paintLabels) {
		this.paintLabels = paintLabels;
	}


	public void setTickColor(Color tickColor) {
		this.tickColor = tickColor;
	}


	public Color getTickColor() {
		return tickColor;
	}


	public void setLabelColor(Color labelColor) {
		this.labelColor = labelColor;
	}


	public Color getLabelColor() {
		return labelColor;
	}


	public HashMap<Double, ParallelLadderTick> getLadderMap() {
		return ladderMap;
	}


}
